<%
# Copyright (C) 2015 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<%
  login_handle_name = @domain_root_account.login_handle_name_with_inference
  # disable form submission when previewing from theme editor
  if params[:previewing_from_themeeditor]
    login_btn_type = forgot_password_btn_type = "button"
  else
    login_btn_type = forgot_password_btn_type = "submit"
  end
%>

<div class="ic-Login">
  <div class="ic-Login__container">
    <div class="ic-Login__content">
      <div class="ic-Login__innerContent">

        <div class="ic-Login-header">
          {{> views/login/shared/header_logo}}
          <div class="ic-Login-header__links">
            <%= render "login/canvas/login_banner" %>
            <% if @domain_root_account.feature_enabled?(:course_catalog) %>
              <a href="/search/all_courses" class="ic-Login__link">
                {{#t}}Browse courses{{/t}}
              </a>
            <% end %>
          </div>
        </div>

        <div class="ic-Login__body">
          <%= form_for :pseudonym_session, :url => url_for({ action: :create }.merge(params.slice(:id).to_unsafe_h)), :html => {:id => "login_form"} do |f| %>
            <h1 class="ui-helper-hidden-accessible">
              {{#t}}Log In{{/t}}
            </h1>
            <% login_inner_dialog = yield :login_inner_dialog %>
            <%= login_inner_dialog if login_inner_dialog && !login_inner_dialog.strip.empty? %>
            <input type="hidden" name="redirect_to_ssl" value="1"/>
            <div class="ic-Form-control ic-Form-control--login">
              <%= f.label :unique_id, login_handle_name, :class => "ic-Label" %>
              <%= f.text_field :unique_id, :class => "ic-Input text", :value => params[:pseudonym_session].try(:[], :unique_id), :autofocus => !params[:previewing_from_themeeditor] %>
            </div>
            <div class="ic-Form-control ic-Form-control--login">
              <%= f.label :password, :en => "Password", :class => "ic-Label" %>
              <%= f.password_field :password, :class => "ic-Input text" %>
            </div>
            <div class="ic-Login__actions">
              <div class="ic-Login__actions-timeout">
                <% unless session_timeout_enabled? %>
                    <%= f.check_box :remember_me, :checked => session[:used_remember_me_token] %>
                    <%= f.label :remember_me, :en => "Stay signed in" %>
                <% end %>

                <div class="ic-Login__forgot">
                  <%= render "login/canvas/forgot_password_link" %>
                </div>
              </div>
              <div class="ic-Form-control ic-Form-control--login">
                <button type="<%= login_btn_type %>" class="Button Button--login">
                  {{#t}}Log In{{/t}}
                </button>
              </div>
            </div> <!-- ic-Login__actions -->
            <%= render partial: "sso_buttons", locals: { aacs: @aacs_with_buttons } %>
          <% end %>
          <%= form_for :pseudonym_session, :url => forgot_password_path, :html => {:id => "forgot_password_form", :style => "display: none;"} do |f| %>
            <p id="forgot_password_instructions" class="ic-Login__forgot-text">
              <%= t('login_handle', "Enter your %{login_handle_name} and we'll send you a link to change your password.", :login_handle_name => login_handle_name) %>
            </p>
            <div class="ic-Form-control ic-Form-control--login">
              <label for="pseudonym_session_unique_id_forgot" class="ic-Label">
                <%= login_handle_name %>
              </label>
              <input aria-describedby="forgot_password_instructions" class="ic-Input email_address text" type="text" name="pseudonym_session[unique_id_forgot]" value="<%= @unauthorized_user.email rescue '' %>" id="pseudonym_session_unique_id_forgot" />

            </div>
            <div class="ic-Form-control ic-Form-control--login">
              <div class="ic-Login__actions">
                <%= link_to t('back_to_login', "Back to Login"), login_path, :class => "ic-Login__actions--left ic-Login__link login_link"%>
                <button type="<%= forgot_password_btn_type %>" class="Button Button--login">
                  {{#t}}Request Password{{/t}}
                </button>
              </div> <!-- end ic-Login__actions -->
            </div>
          <% end %>
        </div> <!-- end ic-Login__body -->
      </div> <!-- end ic-Login__innerContent  -->
      <footer role="contentinfo" id="footer" class="ic-Login-footer">

        <div id="footer-links" class="ic-Login-footer__links">
          <% if Setting.get("show_opensource_linkback", "false") == "true" %>
            <a href="http://instructure.com">
              {{#t}}Open Source LMS{{/t}}
            </a>
          <% end %>
          <%= help_link %>
          {{> views/shared/footer_links}}
        </div>
        <a href="http://www.instructure.com" class="ic-Login-footer__logo-link">
          <%= render "login/canvas/instructure_logo.svg" %>
        </a>
    </footer>
    </div> <!-- end ic-Login__content -->
  </div>
</div> <!-- end ic-Login -->
